package com.chengqs.rainbow.im.gateway.route.strategy.consistent;

import com.chengqs.rainbow.common.core.constant.SymbolConstants;

/**
 * <B>主类名称：</B>VirtualNode<BR>
 * <B>概要说明：</B>虚拟节点<BR>
 *
 * @author: chengqs
 * @create: 2025-09-13 16:42:45
 **/
public class VirtualNode<T extends Node> implements Node {

    /**
     * 物理节点
     */
    final T physicalNode;

    /**
     * 副本索引
     */
    final long replicaIndex;

    public VirtualNode(T physicalNode, long replicaIndex) {
        this.replicaIndex = replicaIndex;
        this.physicalNode = physicalNode;
    }

    @Override
    public String getKey() {
        return physicalNode.getKey() + SymbolConstants.DASH + replicaIndex;
    }

    /**
     * 判断是否为物理节点
     */
    public boolean isVirtualNodeOf(T physicalNode) {
        return physicalNode.getKey().equals(physicalNode.getKey());
    }

    /**
     * 获取物理节点
     */
    public T getPhysicalNode() {
        return physicalNode;
    }
}

